package com.java.fileman;

import java.io.File;

public class FileObject {
	private String name;
	private String path;
	private String type;
	private File file;
	private static AccessObject accessObject;
	private String basePath;
	public FileObject(String path){
		
		file = new File(path);
		basePath = FileServerServlet.prop.getProperty("base.dir");
	}
	public String getName() {
		return file.getName();
	}
	public String getPathPrintable() {
		return file.getPath().substring(0, 10)+".."+file.getPath().substring(file.getPath().length()-10, file.getPath().length()-1);
	}
	public String getPath() {
		String path = file.getPath();
		return path.substring(basePath.length()+1, path.length());
	}
	public String getId() {
		return file.getName();
	}
	public int getType() {
		return file.isFile() ? 1 : 0;
	}
	public String getParent() {
		return file.getParent();
	}
	public static AccessObject getAccessObject() {
		return accessObject;
	}
	public  static void setAccessObject(AccessObject accessObj) {
		accessObject = accessObj;
	}
	public long getSize(){
		if(file.isFile()){
			return file.length();
		}else{
			return 0;
		}
	}
	public String getPermission(){
		String p = file.canRead() ? "r-" : "";
		p += file.canWrite() ? "w-" : "";
		p += file.canExecute() ? "x-" : "";
		return p;
	}
	
}
